package esdclibrarysystem;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author shou1dwe
 */
public class Selection {
    Control control;

    public Selection(){
        control = new Control();
    }
    
    void startService(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int choice= -1;
        while(choice != 0){
            displayMenu();
            try {
                String input = br.readLine();
                choice = Integer.parseInt(input);
            } catch (NumberFormatException ex){
                print("Invalid input");
                continue;
            } catch (IOException ex) {
                Logger.getLogger(Selection.class.getName()).log(Level.SEVERE, null, ex);
            }
            executeChoice(choice);
        }
        return;
    }

    private void displayMenu() {
        print("--------------------------------------------");
        print("             Choose a task:");
        print("--------------------------------------------");
        print(" 1. Register a new member");
        print(" 2. Terminate a membership");
        print(" 3. Add a new title");
        print(" 4. Add a new book");
        print(" 5. Delete a book");
        print(" 6. New loan");
        print(" 7. New return");
        print(" 0. Exit");
        print("--------------------------------------------");
    }

    private void executeChoice(int choice) {
        switch(choice){
            case 0:
                break;
            case 1:
                control.registerAccount();
                break;
            case 2:
                control.terminateMembership();
                break;
            case 3:
                control.addTitle();
                break;
            case 4:
                control.addBook();
                break;
            case 5:
                control.deleteBook();
                break;
            case 6: 
                control.addLoan();
                break;
            case 7:
                control.endLoan();
                break;
            case 8:
                control.getLoans();
                break;
            case 9:
                control.addReservation();
                break;
            case 10:
                control.getReservation();
                break;
            case 11:
                control.findBookByAuthor();
                break;
            case 12:
                control.findBookByTitle();
                break;
            default:
                print("Unknown Choice!");
                break;
        }

    }

    private void print(String string) {
        System.out.println(string);
    }

}
